package com.wiscamp.ninechapters.problems.domain.models.problems.answers;


import com.wiscamp.ninechapters.problems.enums.AnswerTypes;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.stream.Collectors;

/**
 * 多选项答案
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class MultipleOptionAnswer extends Answer {
    /**
     * 答案值 逗号间隔的选项编号文本串
     */
    private Collection<Long> values;

    private String prefix;

    public MultipleOptionAnswer(long answerId, long questionId, int answerIndex, int groupIndex, Collection<Long> values) {
        setAnswerType(AnswerTypes.MULTIPLE_OPTION);
        this.values = values;
        setAnswerId(answerId);
        setQuestionId(questionId);
        setAnswerIndex(answerIndex);
        setGroupIndex(groupIndex);
        setAnswerTypeId(this.getAnswerType().getValue());
    }

    @Override
    public String getAnswerText() {
        var list = values.stream().sorted().collect(Collectors.toList());
        return StringUtils.join(list, ",");
    }

    /*@Override
    public boolean compareAnswer(String contentText) {
        var optionIds = ParseUtils.parseLong(contentText, ",");
        if (optionIds.size() != values.size()) return false;
        for (var correctOptionId : values) {
            var hasOption = false;
            for (var optionId : optionIds) {
                if (optionId == correctOptionId)
                    hasOption = true;
            }
            if (!hasOption) return false;
        }
        return true;
    }*/
}
